//
//  MainController.swift
//  FarmShare
//
//  Created by XingJian Li on 2018/1/18.
//  Copyright © 2018年 aykj. All rights reserved.
//

import Foundation

class MainController: UITabBarController {
    
    let houmeVC = MainIndex()
    let videoVC = MainMessageIndex()
    let userVC = MainUserIndex()
    
    var  navHoume:UINavigationController!
    var  navVideo:UINavigationController!
    var  navUser:UINavigationController!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        
        navHoume = UINavigationController(rootViewController:houmeVC)
        navVideo = UINavigationController(rootViewController:videoVC)
        navUser = UINavigationController(rootViewController:userVC)
        
        self.addChildController(childerVC: navHoume, title: "首页", imageName: "tab_main_n", selectedImageName: "tab_main_s")
        self.addChildController(childerVC: navVideo, title: "消息", imageName: "tab_msg_n", selectedImageName: "tab_msg_s")
        self.addChildController(childerVC: navUser, title: "我的", imageName: "tab_my_n", selectedImageName: "tab_my_s")
        
        tabBar.isTranslucent = false //设置tabBar不透明
        tabBar.tintColor = mainBaseColor //设置选中颜色
        tabBar.backgroundColor = UIColor.white
        tabBar.barTintColor = UIColor.groupTableViewBackground
        //设置文字的颜色
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.gray], for:.normal)
        UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.blue], for:.selected)
            }
    //添加子控制器
    func addChildController(childerVC:UINavigationController,title:String,imageName:String,selectedImageName:String)  {
        
        childerVC.tabBarItem.title = title
        childerVC.tabBarItem.image = UIImage(named:imageName)?.withRenderingMode(.alwaysOriginal)  //使用图片的原始颜色
        childerVC.tabBarItem.selectedImage = UIImage.init(named: selectedImageName)!.withRenderingMode(.alwaysOriginal) //使用图片的原始颜色
      
        self.addChildViewController(childerVC)
    }
    
    
    
}
